//Samantha Midkiff
/* -----------------------------------------------------------------------
 * Include the following lines in your makefile:
 *
 * unitTest2: unitTest2.c dominion.o rngs.o
 *      gcc -o unitTest2 -g  unitTest2.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i, r, p, handCount;
    int maxHandCount = 5;
    int seed = 1000;
    int numPlayer = 2;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int curse_pts = -1, estate_pts = 1, duchy_pts = 3, province_pts = 6, great_hall_pts = 1, gardens_pts = 0;
   
    // arrays victory points cards
    int copper[MAX_HAND];
    int curses[MAX_HAND];
    int estates[MAX_HAND];
    int duchies[MAX_HAND];
    int provinces[MAX_HAND];
    int great_halls[MAX_HAND];

    for (i = 0; i < MAX_HAND; i++)
    {
        curses[i] = curse;
        estates[i] = estate;
        duchies[i] = duchy;
        provinces[i] = province;
        great_halls[i] = great_hall;
        copper[i] =  copper;
    }

    printf ("TESTING scoreFor():\n");
     for (p = 0; p < numPlayer; p++)
    {
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
#if (NOISY_TEST == 1)
                        printf("Test player %d has %d great hall card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], copper, sizeof(int) * handCount); // set all the cards to copper

#if (NOISY_TEST == 1)
           printf("Score = %d, expected = %d\n", scoreFor(p,&G), 0);
#endif
           assert(scoreFor(p,&G) == 0); // check if the number of great hall victory points is correct    
#if (NOISY_TEST == 1)
                        printf("Test player %d has %d great hall card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], great_halls, sizeof(int) * handCount); // set all the cards to great halls

#if (NOISY_TEST == 1)
           printf("Score = %d, expected = %d\n", scoreFor(p,&G), handCount * great_hall_pts);
#endif
           assert(scoreFor(p,&G) == handCount * great_hall_pts); // check if the number of great hall victory points is correct    
           
#if (NOISY_TEST == 1)
                        printf("Test player %d has %d curse card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], curses, sizeof(int) * handCount); // set all the cards to curses

#if (NOISY_TEST == 1)
           printf("Score = %d, expected = %d\n", scoreFor(p,&G), handCount * curse_pts);
#endif
           assert(scoreFor(p,&G) == handCount * curse_pts); // check if the number of curse victory points is correct
           
#if (NOISY_TEST == 1)
                        printf("Test player %d has %d estate card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], estates, sizeof(int) * handCount); // set all the cards to estates

#if (NOISY_TEST == 1)
           printf("Score = %d, expected = %d\n", scoreFor(p,&G), handCount * estate_pts);
#endif
           assert(scoreFor(p,&G) == handCount * estate_pts); // check if the number of estate victory points is correct      
         
#if (NOISY_TEST == 1)
                        printf("Test player %d has %d duchy card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], duchies, sizeof(int) * handCount); // set all the cards to duchies

#if (NOISY_TEST == 1)
           printf("Score = %d, expected = %d\n", scoreFor(p,&G), handCount * duchy_pts);
#endif
           assert(scoreFor(p,&G) == handCount * duchy_pts); // check if the number of duchy victory points is correct    
           
#if (NOISY_TEST == 1)
                        printf("Test player %d has %d province card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], provinces, sizeof(int) * handCount); // set all the cards to provinces

#if (NOISY_TEST == 1)
           printf("Score = %d, expected = %d\n", scoreFor(p,&G), handCount * province_pts);
#endif
           assert(scoreFor(p,&G) == handCount * province_pts); // check if the number of province victory points is correct        
           
        
                }
        }

    printf("All score tests passed!\n");
           
    return 0;
}


